/*
 * 
 * LegendShop 多用户商城系统
 * 
 *  版权所有,并保留所有权利。
 * 
 */
package com.legendshop.oa.dao.impl;

import com.legendshop.dao.impl.GenericDaoImpl;
import com.legendshop.oa.dao.UserManagerDao;
import com.legendshop.oa.model.User;
import com.legendshop.util.AppUtils;

import java.util.List;

/**
 * 针对User的Dao
 */
public class UserManagerDaoImpl extends GenericDaoImpl<User, Long> implements UserManagerDao {
	
	public  Long saveUser(User user){
		return save(user);
	}

	@Override
	public User getUser(Long userId) {
		return getById(userId);
	}

	@Override
	public void updateUser(User user) {
		update(user);
	}

	@Override
	public void deleteUser(User user) {
		delete(user);
	}

	@Override
	public void deleteUseById(Long userId) {
		deleteById(userId);
	}

	/**
	 * 用户是否存在
	 */
	@Override
	public boolean isUserExists(String userName) {
		List<String> list = this.query("select 1 from ls_usr_detail where user_name = ?", String.class, userName);
		return AppUtils.isNotBlank(list);
	}

	@Override
	public User getUserByName(String userName) {
		return get("select id,name,password,enabled,note,dept_id,d.nick_name as nickName,d.shop_id as shopId from ls_user u,ls_usr_detail d where d.user_name = u.name and d.user_name = ?",User.class,userName);
	}
}
